<template>
	<view class="system_page">
		<view>
			<view class="card">
				<view class="border" @click="navigateTo('/pages/system/personal_data')">
					<view>个人资料管理</view>
					<uv-icon name="arrow-right" color="#989898" size="14"></uv-icon>
				</view>
				<view class="border" @click="navigateTo('/pages/login/set_login_pwd')">
					<view>登录密码管理</view>
					<uv-icon name="arrow-right" color="#989898" size="14"></uv-icon>
				</view>
				<view class="border" @click="navigateTo('/pages/login/pay_pwd')">
					<view>支付密码管理</view>
					<uv-icon name="arrow-right" color="#989898" size="14"></uv-icon>
				</view>
				<view class="border" @click="navigateTo('/pages/login/change_phone')">
					<view>修改手机号码</view>
					<uv-icon name="arrow-right" color="#989898" size="14"></uv-icon>
				</view>
			</view>
			<view class="card">
				<view class="border" @click="navigateTo('/pages/system/privacy_agreement?code=8')">
					<view>隐私政策</view>
					<uv-icon name="arrow-right" color="#989898" size="14"></uv-icon>
				</view>

				<view class="border" style="border-bottom: none;" @click="toCancelAccount()">
					<view>注销账号</view>
					<uv-icon name="arrow-right" color="#989898" size="14"></uv-icon>
				</view>
			</view>
			<view class="card" @click="loginOut">
				<view class="log_out">
					退出登录
				</view>
			</view>
		</view>
		<view class="copyright-box">
			<view>Copyright © 2024 - 2074</view>
			<view class="text">菏泽奥坦网络科技有限公司 版权所有</view>
		</view>
	</view>



</template>

<script setup>
	import {
		AccountCancellation,
		GetVersionUpdatingApi
	} from '@/api/modules/system';
	import appUpdate from '@/utils/version_updating.js'
	import useStore from '@/stores';
	import {
		ref
	} from 'vue';
	import {
		compareVersions
	} from '@/utils';

	const modalRef = ref()

	const {
		globalStore
	} = useStore()

	function navigateTo(url) {
		if (url === '/pages/login/pay_pwd') {
			if (globalStore.userInfo?.isCertificate * 1 !== 1) {
				uni.$showModal({
						title: '',
						content: '暂未实名认证，是否前往实名？',
						confirmVal: '确定',
						cancelVal: '取消'
					})
					.then(() => {
						navigateTo('/pages/system/certification')
					})
				return
			}

		}

		uni.navigateTo({
			url
		})
	}

	function loginOut() {
		uni.$showModal({
			title: "",
			content: '是否确定退出此账号？',
			confirmVal: '确定',
			cancelVal: '取消'
		}).then(() => {
			globalStore.logout()
		})
	}

	//	注销账号
	function toCancelAccount() {
		uni.navigateTo({
			url:'/pages/system/cancel_account'
		})
		
	}

	// 	版本更新
	function updateVesion() {
		// #ifdef APP-PLUS
		const {
			platform
		} = uni.getSystemInfoSync();
		GetVersionUpdatingApi({
			type: platform === 'android' ? 1 : 2
		}).then(res => {
			//	版本更新
			if (res.data) {
				plus.runtime.getProperty(plus.runtime.appid, wgtinfo => {

					if (compareVersions(wgtinfo.version, res.data.version) === -1) {
						const updateInfo = {
							platform,
							updateContent: res.data.introduce,
							downUrl: res.data.url,
							version: res.data.version,
							force: false,
							mainColor: '6F69E9',
						}
						appUpdate(updateInfo)
					} else {
						modalRef.value.open()
					}
				})
			} else {
				modalRef.value.open()
			}
		})
		// #endif
	}
</script>

<style lang="scss">
	.system_page {
		// height: calc(100vh - 300rpx);
		width: 100vw;
		padding-top: 30rpx;
		background: #F7F8FB;
		display: flex;
		flex-direction: column;
		justify-content: space-between;

		.card {
			// padding: 0rpx 30rpx 0;
			background: #fff;
			margin-bottom: 20rpx;
			color: #222;
			font-size: 30rpx;

			.border {
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1rpx solid #EBEBEB;
				padding: 30rpx;
			}
			.log_out{
				display: flex;
				align-items: center;
				justify-content: center;
				border-bottom: 1rpx solid #EBEBEB;
				padding: 30rpx 0;
			}
			
		}

		.btn {
			width: 100%;
			font-size: 32rpx;
			font-weight: 500;
			color: #6E68E9;
			line-height: 96rpx;
			text-align: center;
			height: 96rpx;
			margin-bottom: 100rpx;
		}

		.copyright-box {
			margin-top: 20rpx;
			text-align: center;
			font-size: 20rpx;
			color: #ccc;

			.text {
				margin-top: 10rpx;
				margin-bottom: 50rpx;
			}
		}
	}

	.version_box {
		position: relative;
		width: 500rpx;
		height: 600rpx;
		border-radius: 20rpx;
		background: #fff;
		border-radius: 20rpx;
		margin-top: 90rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;

		.image {
			width: 101%;
			position: absolute;
			top: -90rpx;
		}

		.content {
			font-size: 40rpx;
			color: #000;
			margin-top: 180rpx;
		}

		.version_btn {
			width: 240rpx;
			margin-top: 120rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #FFFFFF;
			font-size: 32rpx;
			width: 400rpx;
			font-weight: 700;
			height: 88rpx;
			background: linear-gradient(270deg, #A7A1F6 0%, #6E68E9 100%);
			border-radius: 12rpx;
		}
	}
</style>